/**
 * Created by ospip on 2017/10/10.
 * Copyright (c) 2017 LLAP. All rights reserved.
 */
public class Color {
    protected int value = 0xff000000;

    public static int BLACK = 0xff000000;
    public static int WHITE = 0xffffffff;
    public static int RED = 0xffff0000;
    public static int GREEN = 0xff00ff00;
    public static int BLUE = 0xff0000ff;
    public static int YELLOW = 0xffffff00;
    public static int PURPLE = 0xffff00ff;
    public static int CYAN = 0xff00ffff;

    public static int RGB(int r, int g, int b) {
        if (r < 0 || g < 0 || b < 0 || r > 255 || g > 255 || b > 255) return 0;
        return 0xff000000 | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);
    }

    public Color() {};
    public Color(int c) {
        value = c;
    }

    public Color(int r, int g, int b) {
        value = Color.RGB(r, g, b);
    }

    public int setRED(int v) {
        if (v < 0 || v > 255) return 0;
        value = 0xff00ffff & value | ((v & 0xff) << 16);
        return value;
    }

    public int setGREEN(int v) {
        if (v < 0 || v > 255) return 0;
        value = 0xffff00ff & value | ((v & 0xff) << 8);
        return value;
    }

    public int setBLUE(int v) {
        if (v < 0 || v > 255) return 0;
        value = 0xffffff00 & value | (v & 0xff);
        return value;
    }

    public int getRED() {
        return (value & 0x00ff0000) >> 16;
    }

    public int getGREEN() {
        return (value & 0x0000ff00) >> 8;
    }

    public int getBLUE() {
        return value & 0x000000ff;
    }

    public static void main(String[] args) {
        System.out.println(Color.RGB(255, 255, 0));
        System.out.println(Color.YELLOW);
    }
}
